<template>
  <div>
    <div v-show="show" class="header-img">
      <div class="header-img-pic">
        <img :src="user.headimgurl" alt="">
      </div>
      <span>{{user.nickname}}</span>
    </div>
    <div v-show="!show" class="header-img" >
      <div class="header-img-pic">
        <img src="http://lib.fhdream.com/mobile/img/tx.png?resVer=10000000001" alt="">
      </div>
      <span @click="goLogin">点此登录</span>
    </div>
    <van-cell title="我的订单" is-link to="/index/my-order" />
    <van-cell title="修改密码" is-link to="/reset-pass" />
    <van-button class="login-btn" type="danger" @click="handleSubmit" round size="large">退出登录</van-button>
    <i-footer :active="active"></i-footer>
  </div>
</template>

<script>
  import Footer from '_c/footer'
  export default {
    name: 'my-home',
    components: {
      IFooter: Footer
    },
    data() {
      return {
        active: 3,
        show: false,
        user: {}
      }
    },
    mounted() {
      if (localStorage.getItem('headimgurl')) {
        this.user.headimgurl = localStorage.getItem('headimgurl')
        this.user.nickname = localStorage.getItem('nickname')
        this.show = true
      } else {
        this.show = false
      }
    },
    methods: {
      goLogin() {
        this.$router.push('/login')
      },
      handleSubmit() {
        localStorage.removeItem('x-token')
        localStorage.removeItem('headimgurl')
        localStorage.removeItem('nickname')
        localStorage.removeItem('openId')
        localStorage.removeItem('accessToken')
        this.$router.push('/login')
      }
    }
  }
</script>

<style scoped>
  .header-img{
    width: 100%;
    height: 400px;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .header-img-pic{
    background: #fff;
    border-radius: 50%;
    overflow: hidden;
    width: 130px;
    height: 130px;
  }
  .header-img img{
    width: 100%;
    height: 100%;
  }
  .login-btn{
    width: 84%;
    /*background: #36aaf5;*/
    color: #fff;
    margin: 60px 8%;
  }
</style>
